//三位数加逗号
export const formatNumber = (num: number) => {
    return num.toString().replace(/\d+/, function (n) {
        return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
    })
}

//截取字符串指定项后面的内容
export const getCaption = (str: any, key: string) => {
    const index = str.lastIndexOf(key)
    return str.substring(index + 1, str.length)
}

//数组求和
export const sum = (arr: any[], key: string) => {
    return arr.reduce(function (total, value) {
        return total + value[key];
    }, 0);
}

//数组每一项求和
export const sumItem = (arr: any[]) => {
    return arr.reduce(function (total, value) {
        return total + value;
    }, 0);
}
